/*********************************************************************************************************
 *  ------------------------------------------------------------------------------------------------------
 *  file description
 *  ------------------------------------------------------------------------------------------------------
 *         \file  queue.c
 *        \brief  This is a general-purpose C language queue module, with circular mode and common data structure
 *       \author  Lamdonn
 *        \email  Lamdonn@163.com
 *      \version  1.1.0
 *      \license  GPL2
 *    \copyright  Copyright (C) 2023 Lamdonn.
 ********************************************************************************************************/
#include "vlib.h"

#define IDENT                           (2)

int queue_init(queue_t queue, void* array, int dsize, int capacity)
{
    int ret = deque_init((deque_t)queue, array, dsize, capacity);
    if (!ret) return 0;
    ((deque_t)queue)->parent.ident = IDENT;
    return ret;
}

void queue_deinit(queue_t queue)
{
    deque_deinit((deque_t)queue);
}

queue_t queue_create(int dsize, int capacity)
{
    queue_t queue = (queue_t)deque_create(dsize, capacity);
    if (!queue) return NULL;
    ((deque_t)queue)->parent.ident = IDENT;
    return queue;
}

void queue_delete(queue_t queue)
{
    deque_delete((deque_t)queue);
}

int queue_empty(queue_t queue)
{
    return deque_empty((deque_t)queue);
}

int queue_full(queue_t queue)
{
    return deque_full((deque_t)queue);
}

int queue_size(queue_t queue)
{
    return deque_size((deque_t)queue);
}

int queue_push(queue_t queue, void* data)
{
    return deque_push_back((deque_t)queue, data);
}

int queue_pop(queue_t queue, void* data)
{
    return deque_pop_front((deque_t)queue, data);
}

void queue_clear(queue_t queue)
{
    deque_clear((deque_t)queue);
}

void* queue_data(queue_t queue, int index, int orgin)
{
    return deque_data((deque_t)queue, index, orgin);
}

int queue_insert(queue_t queue, int index, void* data, int orgin)
{
    return deque_insert((deque_t)queue, index, data, orgin);
}

int queue_erase(queue_t queue, int begin, int end, int orgin)
{
    return deque_erase((deque_t)queue, begin, end, orgin);
}

int queue_read(queue_t queue, int index, void* data, int orgin)
{
    return deque_read((deque_t)queue, index, data, orgin);
}

int queue_modify(queue_t queue, int index, void* data, int orgin)
{
    return deque_modify((deque_t)queue, index, data, orgin);
}

int queue_capacity(queue_t queue)
{
    return deque_capacity((deque_t)queue);
}

int queue_alter_capacity(queue_t queue, int capacity)
{
    return deque_alter_capacity((deque_t)queue, capacity);
}

void queue_mode(queue_t queue, int mode, int set)
{
    deque_mode((deque_t)queue, mode, set);
}
